package com.chenglai.goods.controller;

import com.chenglai.commonutils.common.Result;
import com.chenglai.commonutils.common.StatusCode;
import com.chenglai.goods.service.GoodsLoopService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author yawang
 * @create 2023/11/16 14:35:15
 **/
@RestController
@RequestMapping("/goodsLoop")
public class GoodsLoopController {

    @Autowired
    private GoodsLoopService goodsLoopService;

    @PostMapping("/listLoops")
    @ApiOperation(value = "获取轮播图图片集")
    public  Result listLoops(@ApiParam(name="shopId",value = "门店ID") Integer shopId,
                             @ApiParam(name="page",value = "页码") Integer page,
                             @ApiParam(name="size",value = "每页条数") Integer size,
                             @ApiParam(name="loopName",value = "名称") String loopName){
        try {
            PageInfo results = goodsLoopService.listLoops(page,size,shopId,loopName);
            return new Result(true, StatusCode.OK,"查询成功",results);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }

    @PostMapping("/addLoops")
    @ApiOperation(value = "批量添加轮播图图片集")
    public  Result addLoops(HttpServletRequest request){
        try {
            goodsLoopService.addLoops(request);
            return new Result(true, StatusCode.OK,"操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"操作失败");
        }
    }

    @PostMapping("/delLoops")
    @ApiOperation(value = "批量删除轮播图图片集")
    public  Result delLoops(@ApiParam(name="ids",value = "图片ID字符串") String ids){
        try {
            goodsLoopService.delLoops(ids);
            return new Result(true, StatusCode.OK,"操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"操作失败");
        }
    }
    @PostMapping("/updatePicName")
    @ApiOperation(value = "图片重命名")
    public  Result updatePicName(@ApiParam(name="loopId",value = "图片ID串") Integer loopId,
                                 @ApiParam(name="loopName",value = "名称") String  loopName){
        try {
            goodsLoopService.updatePicName(loopId,loopName);
            return new Result(true, StatusCode.OK,"操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"操作失败");
        }
    }

}
